/*
 * StrahlentherapieRun.cc
 *
 *  Created on: Nov 26, 2010
 *      Author: holger
 */

#include "StrahlentherapieRun.hh"
#include "G4Run.hh"
#include "G4Event.hh"
#include "G4THitsMap.hh"
#include "G4SDManager.hh"

StrahlentherapieRun::StrahlentherapieRun() : nEvent(0)
{
	G4SDManager* SDM = G4SDManager::GetSDMpointer();
	totalEnergyHeadID = SDM->GetCollectionID("headSD/energyDep");
	totalDoseHeadID = SDM->GetCollectionID("headSD/doseDep");
	
	totalEnergyDetectorPlateID = SDM->GetCollectionID("detectorPlateSD/energyDep");
}

StrahlentherapieRun::~StrahlentherapieRun()
{}

void StrahlentherapieRun::RecordEvent(const G4Event * event)
{
	nEvent++;
	G4HCofThisEvent* HCE = event->GetHCofThisEvent();
	
	if(totalEnergyHeadID != -1) {
		eventTotalEnergyHead = (G4THitsMap<G4double>*)(HCE->GetHC(totalEnergyHeadID));
		totalEnergyHead += *eventTotalEnergyHead;
	}
	if(totalDoseHeadID != -1) {
		eventTotalDoseHead = (G4THitsMap<G4double>*)(HCE->GetHC(totalDoseHeadID));
		totalDoseHead += *eventTotalDoseHead;
	}
	
	if(totalEnergyDetectorPlateID != -1) {
		eventTotalEnergyDetectorPlate = (G4THitsMap<G4double>*)(HCE->GetHC(totalEnergyDetectorPlateID));
		totalEnergyDetectorPlate += *eventTotalEnergyDetectorPlate;
	}
}
